package com.yuhs.zixing.study.design.pattern.dp002.structural.s004.composite.c003;

import java.util.ArrayList;

/**
 * @description:
 * @author: yuhs
 * @date: 2022/5/1 10:09 PM
 */
public class Client003 {
    //遍历整棵树,只要给我根节点，我就能遍历出所有的节点
    public static String getTreeInfo(Branch003 root) {
        ArrayList<Corp003> subordinateList = root.getSubordinate();
        String info = "";
        for (Corp003 s : subordinateList) {
            if (s instanceof Leaf003) { //是员工就直接获得信息
                info = info + s.getInfo() + "\n";
            } else { //是个小头目
                info = info + s.getInfo() + "\n" + getTreeInfo((Branch003) s);
            }
        }
        return info;
    }

    public static void main(String[] args) {
        //首先是组装一个组织结构出来
        Branch003 ceo = compositeCorpTree();
        //首先把CEO的信息打印出来
        System.out.println(ceo.getInfo());
        //然后是所有员工信息
        System.out.println(getTreeInfo(ceo));
    }

    //把整个树组装出来
    public static Branch003 compositeCorpTree() {
        //首先产生总经理CEO
        Branch003 root = new Branch003("王大麻子", "总经理", 100000);
        //把三个部门经理产生出来
        Branch003 developDep = new Branch003("刘大瘸子", "研发部门经理", 10000);
        Branch003 salesDep = new Branch003("马二拐子", "销售部门经理", 20000);
        Branch003 financeDep = new Branch003("赵三驼子", "财务部经理", 30000);
        //再把三个小组长产生出来
        Branch003 firstDevGroup = new Branch003("杨三乜斜", "开发一组组长", 5000);
        Branch003 secondDevGroup = new Branch003("吴大棒槌", "开发二组组长", 6000);
        //把所有的小兵都产生出来
        Leaf003 a = new Leaf003("a", "开发人员", 2000);
        Leaf003 b = new Leaf003("b", "开发人员", 2000);
        Leaf003 c = new Leaf003("c", "开发人员", 2000);
        Leaf003 d = new Leaf003("d", "开发人员", 2000);
        Leaf003 e = new Leaf003("e", "开发人员", 2000);
        Leaf003 f = new Leaf003("f", "开发人员", 2000);
        Leaf003 g = new Leaf003("g", "开发人员", 2000);
        Leaf003 h = new Leaf003("h", "销售人员", 5000);
        Leaf003 i = new Leaf003("i", "销售人员", 4000);
        Leaf003 j = new Leaf003("j", "财务人员", 5000);
        Leaf003 k = new Leaf003("k", "CEO秘书", 8000);
        Leaf003 zhengLaoLiu = new Leaf003("郑老六", "研发部副经理", 20000);
        //开始组装
        //CEO下有三个部门经理和一个秘书
        root.addSubordinate(k);
        root.addSubordinate(developDep);
        root.addSubordinate(salesDep);
        root.addSubordinate(financeDep);
        //研发部经理
        developDep.addSubordinate(zhengLaoLiu);
        developDep.addSubordinate(firstDevGroup);
        developDep.addSubordinate(secondDevGroup);
        //看看两个开发小组下有什么
        firstDevGroup.addSubordinate(a);
        firstDevGroup.addSubordinate(b);
        firstDevGroup.addSubordinate(c);
        secondDevGroup.addSubordinate(d);
        secondDevGroup.addSubordinate(e);
        secondDevGroup.addSubordinate(f);
        //再看销售部下的人员情况
        salesDep.addSubordinate(h);
        salesDep.addSubordinate(i);
        //最后一个财务
        financeDep.addSubordinate(j);
        return root;
    }
}
